package com.colt.contentcenter.sentineldemo;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: content-center
 * @description: 区分来源
 * @author: colt
 * @create: 2020-06-28 11:25
 **/
//@Component
public class MyRequestOriginParser implements RequestOriginParser {
    @Override
    public String parseOrigin(HttpServletRequest request) {
        //从请求参数中获取 名为origin的参数
        //如果获取不大到origin参数   抛出异常
        String origin = request.getParameter("origin");
        if (StringUtils.isBlank(origin)){
            throw new IllegalArgumentException("origin must be specifid");
        }
        return origin;
    }
}
